<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('money_transactions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('用户ID');
            $table->unsignedBigInteger('category_id')->comment('主分类ID');
            $table->unsignedBigInteger('sub_category_id')->comment('子分类ID');
            $table->tinyInteger('type')->comment('交易类型：1收入，2支出');
            $table->decimal('amount', 10, 2)->comment('金额');
            $table->date('transaction_date')->comment('交易日期');
            $table->string('description', 255)->nullable()->comment('交易描述');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('category_id')->references('id')->on('money_categories')->onDelete('cascade');
            $table->foreign('sub_category_id')->references('id')->on('money_sub_categories')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('money_transactions');
    }
};
